import {Command} from '../constant';
import Taro from '@tarojs/taro';
import {Dispatch} from 'typings';
import {IAllReducerProps} from '../types';
import {getReducerData} from '@/redux/store';
import {extraPathsValue} from '@/redux/util';
import api from 'api';

export default (dispatch: Dispatch) => {
  let action = {
    commonChange(...param: any) {
      dispatch({
        type: Command.commonChange,
        payload: extraPathsValue(...arguments),
      });
    },
    async page() {
      const {
        main: {isAquamarineMember, isCrystalMember},
      } = getData();
      let memberType = null;
      if (isAquamarineMember && isCrystalMember) {
        //双会员
        memberType = 2;
      } else if (isAquamarineMember && !isCrystalMember) {
        //蓝晶会员
        memberType = 0;
      } else if (!isAquamarineMember && isCrystalMember) {
        //赤晶会员
        memberType = 1;
      }
      let params = {
        enterWay: 1,
        // memberType: memberType, //memberType会员类型：0-蓝晶会员 1-赤晶会员 2双会员
      };
      const res = await api.OnecategoryController.findOnecategoryList(params); //查询权益类目-首页入口
      action.commonChange('main.list', res);
    },
  };
  return action;
};

function getData(): IAllReducerProps {
  return {
    main: getReducerData('packageDCommunityService'),
  };
}

//create by moon https://github.com/creasy2010/moon
